package com.pig4cloud.pig.myvideos.service;


import cn.hutool.core.codec.Base64;
import cn.hutool.core.text.UnicodeUtil;
import cn.hutool.json.JSONUtil;
import com.pig4cloud.pig.myvideos.service.impl.MyvideosServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.io.IOException;
import java.util.SortedMap;
import java.util.TreeMap;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;

@RunWith(JUnit4.class)
public class MyvideosServiceTestNoSpring {

	@Test
	public void HutoolCrypto() {
//		"""
//		从java后台传过来的视频参数
//			param_j         {"jId": "7021124933367385346", "myTitleCn": "小慧君超强cos 是天使喔~~~", "myTagsCn": "#cosplay #小姐姐 #小慧君"}
//							{"jId": "7021124933367385346", "myTitleCn": "\u5c0f\u6167\u541b\u8d85\u5f3acos \u662f\u5929\u4f7f\u5594~~~", "myTagsCn": "#cosplay #\u5c0f\u59d0\u59d0 #\u5c0f\u6167\u541b"}
//			param_b64       eyJqSWQiOiAiNzAyMTEyNDkzMzM2NzM4NTM0NiIsICJteVRpdGxlQ24iOiAiXHU1YzBmXHU2MTY3XHU1NDFiXHU4ZDg1XHU1ZjNhY29zIFx1NjYyZlx1NTkyOVx1NGY3Zlx1NTU5NH5+fiIsICJteVRhZ3NDbiI6ICIjY29zcGxheSAjXHU1YzBmXHU1OWQwXHU1OWQwICNcdTVjMGZcdTYxNjdcdTU0MWIifQ==
//		"""
		SortedMap<String, String> sortedMap = new TreeMap<String, String>();
		sortedMap.put("jId", "7021124933367385346");
		sortedMap.put("myTitleCn", "小慧君超强cos 是天使喔~~~");
		sortedMap.put("myTagsCn", "#cosplay #小姐姐 #小慧君");
		String j = JSONUtil.toJsonStr(sortedMap);
		j = UnicodeUtil.toUnicode(j);
		assertEquals(j, "{\"jId\":\"7021124933367385346\",\"myTagsCn\":\"#cosplay #\\u5c0f\\u59d0\\u59d0 #\\u5c0f\\u6167\\u541b\",\"myTitleCn\":\"\\u5c0f\\u6167\\u541b\\u8d85\\u5f3acos \\u662f\\u5929\\u4f7f\\u5594~~~\"}");

		// 测试Base64
		j = "{\"jId\": \"7021124933367385346\", \"myTitleCn\": \"\\u5c0f\\u6167\\u541b\\u8d85\\u5f3acos \\u662f\\u5929\\u4f7f\\u5594~~~\", \"myTagsCn\": \"#cosplay #\\u5c0f\\u59d0\\u59d0 #\\u5c0f\\u6167\\u541b\"}";
		String encode = Base64.encode(j);
		System.out.println(encode);
		assertEquals(encode, "eyJqSWQiOiAiNzAyMTEyNDkzMzM2NzM4NTM0NiIsICJteVRpdGxlQ24iOiAiXHU1YzBmXHU2MTY3XHU1NDFiXHU4ZDg1XHU1ZjNhY29zIFx1NjYyZlx1NTkyOVx1NGY3Zlx1NTU5NH5+fiIsICJteVRhZ3NDbiI6ICIjY29zcGxheSAjXHU1YzBmXHU1OWQwXHU1OWQwICNcdTVjMGZcdTYxNjdcdTU0MWIifQ==");
	}

    @Test
    public void execCmd() throws IOException, InterruptedException {
		Process pro = Runtime.getRuntime().exec("cmd.exe /c dir c:");
		int exitVal = pro.waitFor();
		System.out.println(exitVal);
		System.out.println(pro);
	}

	@Test
	public void autoShipinhao() {
		MyvideosService service = new MyvideosServiceImpl();
		boolean ret = service.FabuShipinhao("7021124933367385346", "小慧君超强cos 是天使喔~~~", "#cosplay #小姐姐 #小慧君");
		assertTrue(ret);
	}
}
